package oop.data;

import java.sql.SQLException;
import java.util.List;

import oop.db.dao.LevelConstraintDAO;
import oop.db.dao.MarkConstraintDAO;
import oop.db.dao.TestStructureDAO;
import oop.db.dao.TopicConstraintDAO;

public class SectionStructure {

	private long id;
	private long testStructureId;
	private int order;
	private String text;
	private List<TopicConstraint> topicConstrains = null;
	private List<LevelConstraint> levelConstrains = null;
	private List<MarkConstraint> markConstrains = null;

	public SectionStructure(long id, String text, long testStructureId, int order) {
		super();
		this.id = id;
		this.testStructureId = testStructureId;
		this.order = order;
		this.text = text;
	}

	public int getOrder() {
		return order;
	}

	public void setOrder(int order) {
		this.order = order;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public long getId() {
		return id;
	}

	public List<TopicConstraint> getTopicConstraints() throws SQLException {
		if (topicConstrains == null) {
			topicConstrains = TopicConstraintDAO.fetchBySectionStructure(id);
		}
		return topicConstrains;
	}
	
	public List<LevelConstraint> getLevelConstraints() throws SQLException {
		if (levelConstrains == null) {
			levelConstrains = LevelConstraintDAO.fetchBySectionStructure(id);
		}
		return levelConstrains;
	}

	public List<MarkConstraint> getMarkConstraints() throws SQLException {
		if (markConstrains == null) {
			markConstrains = MarkConstraintDAO.fetchBySectionStructure(id);
		}
		return markConstrains;
	}
	
	public TestStructure getTestStructure() throws SQLException {
		return TestStructureDAO.fetchById(testStructureId).get(0);
	}
	
}
